package org.swfer.UICExtend 
{
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	
	
	[Event(name='complete',type='flash.events.Event')]
	
	/**
	 * swf皮肤管理器
	 * @author swfer
	 */
	public class SkinManager extends EventDispatcher
	{
		private var loader:Loader;
		private var _isComplete:Boolean;
		
		public function SkinManager() 
		{
			loader = new Loader();
		}
		
		public function get isComplete():Boolean 
		{
			return _isComplete;
		}
		
		public function loadBytes(bytes:ByteArray):void
		{
			loader.contentLoaderInfo.addEventListener(Event.INIT, loadComplete);
			loader.loadBytes(bytes);
		}
		
		public function loadSkin(url:String):void
		{
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete);
			loader.load(new URLRequest(url));
		}
		
		private function loadComplete(e:Event):void 
		{
			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadComplete);
			loader.contentLoaderInfo.removeEventListener(Event.INIT, loadComplete);
			_isComplete = true;
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		public function getSkin(skinName:String):MovieClip
		{
			return new (loader.contentLoaderInfo.applicationDomain.getDefinition(skinName) as Class)() as MovieClip;
		}
	}

}